package com.motorola.accessories;

public class MotWhisperAccessoryPowerSupply {
    // This 2 bit field defines the version of the power definition. This value is
    // 00 for the following definition. All other values are reserved for future expansion.
    public static int VERSION_REQUIRED = 17; // 2 bits 18-17
    // This 6 bit field defines what the maximum current that the main supply is capable of
    // providing. The first 32 levels are 300mA-1850mA in 50mA increments.
    // The next 32 levels 1900mA-5000mA in 100mA increments.
    public static int MAIN_CURRENT     = 10;
    // This 4 bit field defines the secondary voltage capability of the power supply. It
    // defines values from 4V-19V in 1V increments.
    // Note: if both the secondary voltage and current field are all ones, no secondary supply
    // is present in the power supply.
    public static int SECONDARY_VOLTAGE  = 6;

    // This 6 bit field defines the secondary current capability of the power supply. It
    // defines 32 levels from 300mA-1850mA in 50mA increments and
    // 32 levels 1900mA-5000mA in 100mA increments.
    public static int SECONDARY_CURRENT  = 1;

    // This single bit field defines the power source of the power supply. A zero indicates
    // the power source is line power. A one indicates that the power
    // source is a vehicular power adapter.
    public static int SOURCE = 0;

    private MotWhisperAccessoryPowerSupply() { } // class cannot be instantiated

    public static int getVersionRequired(String accessory_id) {
        if ( MotWhisperAccessoryAdapter.getClassType(accessory_id) ==
                            MotWhisperAccessoryAdapter.CLASS_TYPE_POWER_SUPPLY ) {
            return ( (MotWhisperAccessoryAdapter.getSemuID(accessory_id)>>VERSION_REQUIRED) & 0x03  ); // not validated
        }
        return 0;
    }

    public static int getMainCurrent(String accessory_id) {
        if ( MotWhisperAccessoryAdapter.getClassType(accessory_id) ==
                            MotWhisperAccessoryAdapter.CLASS_TYPE_POWER_SUPPLY ) {
           return ( (MotWhisperAccessoryAdapter.getSemuID(accessory_id)>>MAIN_CURRENT) & 0x3F  );     // not validated
        }
        return 0;
    }

    public static int getSecondaryVoltage(String accessory_id) {
        if ( MotWhisperAccessoryAdapter.getClassType(accessory_id) ==
                            MotWhisperAccessoryAdapter.CLASS_TYPE_POWER_SUPPLY ) {
            return ( (MotWhisperAccessoryAdapter.getSemuID(accessory_id)>>SECONDARY_VOLTAGE) & 0x0F  );     // not validated
        }
        return 0;
    }
    public static int getSecondaryCurrent(String accessory_id) {
        if ( MotWhisperAccessoryAdapter.getClassType(accessory_id) ==
                            MotWhisperAccessoryAdapter.CLASS_TYPE_POWER_SUPPLY ) {
            return ( (MotWhisperAccessoryAdapter.getSemuID(accessory_id)>>SECONDARY_CURRENT) & 0x3F  );     // not validated
        }
        return 0;
    }
    public static int isSourceVehiclePowered(String accessory_id) {
        if ( MotWhisperAccessoryAdapter.getClassType(accessory_id) ==
                            MotWhisperAccessoryAdapter.CLASS_TYPE_POWER_SUPPLY ) {
            return ( (MotWhisperAccessoryAdapter.getSemuID(accessory_id)>>SOURCE) & 0x01  );     // not validated
        }
        return 0;
    }
}
